﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;
using System.Data;

namespace ConfExpert.Forms.Ithalat
{
    public partial class BarsanDosyaEkle : XForm
    {
        DataSet d;
        public BarsanDosyaEkle(DataSet d)
        {
            InitializeComponent();
            this.d = d;
        }

        private void BarsanDosyaEkle_Load(object sender, EventArgs e)
        {
            gridView1.Init(d.Tables[0]);
            gridView1.AddDetailGrid(gridView2, "REFERANS");

            gridView2.Columns["Miktar"].ColumnEdit =
                gridView2.Columns["FaturaTutar"].ColumnEdit = new DevExpress.XtraEditors.Repository.RepositoryItemCalcEdit();
            gridView2.FormatAsNumber(2, "Miktar", "FaturaTutar");
            gridView1.AddColumn("LineCount", typeof(int), "COUNT(Child({FK}).FaturaNo)");
            gridView1.MakeReadOnly();
            gridView2.EnableNewRow();

            btnKaydet.ItemClick += btnKaydet_ItemClick;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView2.EndEditing();
            int Eksik = d.Tables[0].Select("LineCount<1").Length;
            if (Eksik > 0)
            {
                ShowErrorMessage("Commercial invoice bilgisi girilmemiş " + Eksik.ToStr() + " referans var! Tamamlamadan kaydedemezsiniz.");
                return;
            }

            string xml = gridView2.Serialize();
            ExecuteNonQuery("UpdBarsanDosyasiEkle", xml);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
